package com.heo.coder.packet;

import com.heo.coder.packet.base.BasePacket;
import com.heo.util.ByteHelper;
import com.heo.util.Utils;

public class HeartbeatPacketRsp extends BasePacket{

	public HeartbeatPacketRsp(String head, String id, int bodyLength, String msta,
			String control, String body, String check) throws Exception {
		super(head, id, bodyLength, msta, control, body, check);
	}
	
	/**
	 * 
	 * @param apn
	 * @param domain
	 * @param port
	 * @param sleepTime 关锁情况下，多久上传一次位置 单位s
	 * @param workTime  开锁情况下，多久上传一次位置 单位s
	 */
	public void setMsgContent() {
		setBodyLengthStr(ByteHelper.strReversal(ByteHelper.intToHexString(4, 4)));
		String timeStamp = Utils.timeStamp();
		String timeCode = ByteHelper.intToHexString(Utils.getInteger(timeStamp), 8);
		setBody(ByteHelper.strReversal(timeCode.toUpperCase()));
		String check = ByteHelper.makeCheckSum(START_MARKER_LENGTH_CODE + getHead() + getMsta() + getId() + START_MARKER_LENGTH_CODE + getControl() + getBodyLengthStr() + getBody());
		setCheck(check);
	}
	
	@Override
	public String toString() {
		return "SocketPacket: [" + control + "] [" + START_MARKER_LENGTH_CODE + getHead() + getMsta() + getId() + START_MARKER_LENGTH_CODE + getControl() +  getBodyLengthStr() + getBody() + getCheck() + END_MARKER_LENGTH_CODE + "]";
	}

	@Override
	public String getPacketBody() {
		return super.body;
	}

	
	
}
